package site.luojie.transfer.service.impl;

import site.luojie.transfer.dao.AccountDao;
import site.luojie.transfer.domian.Account;
import site.luojie.transfer.service.AccountService;

/**
 * @Description:
 * @Author jie.luo
 * @Create: 2020-04-30 23:39
 **/
public class AccountServiceImpl implements AccountService {

    // 通过 new 实例化对象
//    private AccountDao accountDao = new JdbcAccountDaoImpl();
//    private AccountDao accountDao = (AccountDao) BeanFactory.getInstance().getBean("accountDao");
    private AccountDao accountDao;

    @Override
    public void accountTransfer(String accountSource, String accountTarget, Integer money) throws Exception {

        Account source = accountDao.selectAccountByNumber(accountSource);
        Account target = accountDao.selectAccountByNumber(accountTarget);

        source.setBalance(source.getBalance() - money);
        target.setBalance(target.getBalance() + money);

        accountDao.updateAccountBalance(source);
        int i = 1 / 0;
        accountDao.updateAccountBalance(target);
    }

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }
}
